//前端非空验证（标签ID，提示语）
function nonEmpty(input, tips) {
    var inputval = $("#" + input).val();
    if (!inputval) {
        layer.tips('请输入'+tips+'!', '#' + input, {tips: [2, '#CC3333']});
        return false;
    }
    return true;
}

//用户名验证
function accountCheck(input, tips){
    if(nonEmpty(input, tips)){
        // selectUserName(true);

    var account = $("#account").val();
    $.ajax({
        url : "manageWork/accountCheck.action",
        data : {
            "account" : account
        },
        type : "post",
        dataType : "text",
        success : function (result) {
            if (result=="error") {
                    layer.tips('用户名可用！', '#account11', {tips: [2, '#00ff00']});
            } else if (result=="success") {
                layer.tips('用户名已被使用！', '#account11', {tips: [2, '#CC3333']});
            }
        }
    });
    }
}
//密码验证
function pwdCheck(input, tips){
    if (nonEmpty(input, tips)) {
        var password = $("#password").val();
        var password2 = $("#password2").val();
        if (password != password2) {
            layer.tips('密码不一致！', '#password2', {tips: [2, '#CC3333']});
        }
    }
}

//验证年龄
function workAgeCheck(input, tips){
    if(nonEmpty(input, tips)){
        var workAge = $("#workAge").val();
        if(workAge > 150  || workAge <= 0){
            layer.tips('年龄格式有误！', '#workAge', {tips: [2, '#CC3333']});
        }
    }
}

//手机验证
function modeleCheck(input, tips){
    if (nonEmpty(input, tips)) {
        var inputval = $("#"+input).val();
            if (!inputval.match(/^1[34578]\d{9}$/)) {
                layer.tips('请输入正确的'+tips+'！', '#'+input, {tips: [2, '#CC3333']});
            }
    }
}

//增加内部工作人员
function submission1() {
    if ($("#workName").val() == "") {
        alert("带*号的为必填，请重新填写！！")
        return;
    };
    if ($("#account").val() == "") {
         alert("带*号的为必填，请重新填写！！")
         return;
    };
    if ($("#password").val() == "") {
        alert("带*号的为必填，请重新填写！！")
        return;
     };
    if ($("#password2").val() == "") {
        alert("带*号的为必填，请重新填写！！")
        return;
    };
    if ($("#workAge").val() == "") {
        alert("带*号的为必填，请重新填写！！")
        return;
    };
    if ($("#mobile").val() == "") {
        alert("带*号的为必填，请重新填写！！")
        return;
    };
    if ($("#post").val() == "") {
        alert("带*号的为必填，请重新填写！！")
        return;
    };
    if ($("#education").val() == "") {
        alert("带*号的为必填，请重新填写！！")
        return;
    };

        if ($("#deskId").val() == 0) {
            alert("带*号的为必填，请重新填写！！")
            return;
        };
        if ($("#roleId").val() == 0) {
            alert("带*号的为必填，请重新填写！！")
            return;
        };
        if ($("#workSite").val() == "") {
            alert("带*号的为必填，请重新填写！！")
            return;
        };

        var password = $("#password").val();
        var password2 = $("#password2").val();
        if (password != password2) {
            alert("密码不一致，请从新输入！！")
            return;
        };

        var workName = $("#workName").val();
        var account = $("#account").val();
        var workPwd = $("#password2").val();
        var workSex = $("input[name='workSex']:checked").val();
        var workAge = $("#workAge").val();
        var mobile = $("#mobile").val();
        var post = $("#post").val();
        var education = $("#education").val();
        // var deskId = $("select[name='deskId']::value").val();
        var deskId = $("#deskId").val();
        var roleId = $("#roleId").val();
        // var roleId = $("select[name='roleId']::value").val();
        var workSite = $("#workSite").val();

        $.ajax({
            url: "manageWork/addWork.action",
            data: {
                "workName": workName,
                "account": account,
                "workPwd": workPwd,
                "workSex": workSex,
                "workAge": workAge,
                "mobile": mobile,
                "post": post,
                "education": education,
                "deskId": deskId,
                "roleId": roleId,
                "workSite": workSite
            },
            type: "post",
            dataType: "text",
            success: function (res) {
                if (res == "success") {
                    layer.msg("添加成功！！", {icon: 6, time: 1000}, function () {
                        layer.closeAll(layer.index);
                        window.parent.location.reload()
                    });
                } else if (res == "error") {
                    layer.msg("添加失败！！", {icon: 6, time: 1000}, function () {
                        layer.closeAll(layer.index);
                        window.parent.location.reload()
                    });
                }
            }
        });


}

